<?php

/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: correctioninfo.inc.php 4511 2010-09-19 00:51:25Z yumiao $
 */

if(!defined('IN_ADMIN')) {
	exit('Acess Denied');
}

require_once(B_ROOT.'./source/adminfunc/tool.func.php');

$operation = trim($_POST['operation']);
$resolved = intval($_GET['resolved']);
$wheresql = '';

if($resolved) {
	$selected[1] = 1;
	$wheresql = ' AND status=1';
	$correctioninfoop = ', \'correctioninfoop\'';
} else {
	$selected[0] = 1;
	$wheresql = ' AND status=0';
}
if(!ckfounder($_G['uid'])) {
    $query = DB::query("SELECT itemid FROM ".DB::table("shopitems")." WHERE catid IN (".$_SGLOBAL['adminsession']['cpgroupshopcats'].")");
    while($result = DB::fetch($query)) {
        $shopitems[] = $result['itemid'];
    }
    if(!empty($shopitems)) {
        $wheresql .= ' AND shopid IN ('.implode(",", $shopitems).')';
    } else {
        $wheresql .= ' AND shopid IN (0)';
    }
}
if(!empty($wheresql)) {
	$wheresql = ' WHERE'.substr($wheresql, 4);
}
shownav('shop', 'correctioninfo_list');
showsubmenu('correctioninfo_list', array(
	array('mod_notresolved', 'correctioninfo', $selected[0]),
	array('mod_resolved', 'correctioninfo&resolved=1', $selected[1])
));
showtips('correctioninfo_list_tips');

if(submitcheck('deletesubmit')) {

	if(empty($_POST['correctioninfo'])) {
		cpmsg('notselect_item');
	}
	if($operation == 'updatestatus' && !isset($_POST['resolved'])) {
		cpmsg('correctinfo_notselect_status');
	}

	$status = intval($_POST['resolved']);
	$correctioninfos = implode(',', $_POST['correctioninfo']);

	if($operation == 'delete') {
		DB::query("DELETE FROM ".DB::table('correctioninfos')." WHERE correctioninfoid IN ($correctioninfos)");
	} elseif($operation == 'updatestatus') {
		DB::query("UPDATE ".DB::table("correctioninfos")." SET `status` = $status WHERE correctioninfoid IN ($correctioninfos)");
	}
	cpmsg('message_success', 'admin.php?action=correctioninfo');
}

$subtitles = array('<input type="checkbox" onclick="checkall(this.form, \'correctioninfo\')" name="chkall" checked>', 'correctioninfoid', 'correctioninfousername', 'correctioninfoshopname', 'correctioninforeason', 'correctioninfotime', 'correctioninfoop');
$resolved == 1 && array_pop($subtitles);

showformheader('correctioninfo');
showtableheader('');
showsubtitle($subtitles);

$correctioninfo = $correctioninfoarr = array();
$tpp = 15;
$page = $_GET['page'] > 0 ? intval($_GET['page']) : 1;
$rstart = ($page - 1) * $tpp;
$query = DB::query("SELECT count(correctioninfoid) AS count  FROM ".DB::table('correctioninfos')." $wheresql;");
$value = DB::fetch($query);
$multipage = multi($value['count'], $tpp, $page, 'admin.php?action=correctioninfo', $phpurl=1);
$query = DB::query("SELECT * FROM ".DB::table('correctioninfos')." $wheresql ORDER BY dateline DESC LIMIT ".$rstart.", ".$tpp.";");
while($correctioninfo = DB::fetch($query)) {
	$correctioninfo['shopname'] = DB::result_first("SELECT subject FROM ".DB::table('shopitems')." WHERE itemid='$correctioninfo[shopid]'");
	$correctioninfo['shortreason'] = cutstr($correctioninfo['reason'], 30, 1);
	$correctioninfo['resolvedlang'] = $correctioninfo['status'] == 1 ? '' : $lang['correctinfo_to_resolve'];
	$correctioninfoarr[] = $correctioninfo;
}
foreach($correctioninfoarr as $value) {
	$tablerows = array('<input class="checkbox" type="checkbox" name="correctioninfo[]" value="'.$value['correctioninfoid'].'" checked/>', $value['correctioninfoid'], $value['username'], '<a href=\'store.php?id='.$value['shopid'].'\' target=\'_blank\'>'.$value['shopname'].'</a>', '<span title="'.$value['reason'].'">'.$value['shortreason'].'</span>', date('Y-m-d', $value['dateline']), '<a href=\'admin.php?action=edit&m=shop&itemid='.$value['shopid'].'\' target=\'_blank\'>'.$value['resolvedlang'].'</a>');
	$resolved == 1 && array_pop($tablerows);
	showtablerow('', array(), $tablerows);
}
showtablefooter();
echo $multipage;
showcorrectinfomod();
showformfooter();
bind_ajax_form();
?>